﻿using UnityEngine;
using System;


namespace Network 
{
    public delegate void onSendMsgStarted(byte[] f_data);
    public delegate void onSendMsgFinished(bool f_success);

    public class NetUtilites : MonoBehaviour
    {
        private const string PortReleaseGuid = "887SBD8E55W";

        /// <summary>
        /// 把UShort大端小端转换一下
        /// </summary>
        /// <param name="f_value"></param>
        /// <returns></returns>
        public static ushort ByteReverse_ushort(ushort f_value)
        {
            byte[] data = BitConverter.GetBytes(f_value);
            return ByteReverse_ushort(data);
        }

        public static ushort ByteReverse_ushort(byte[] f_data)
        {
            byte tmp = f_data[0];
            f_data[0] = f_data[1];
            f_data[1] = tmp;
            return BitConverter.ToUInt16(f_data, 0);
        }

        public static int ByteReverse_int(int f_value)
        {
            byte[] data = BitConverter.GetBytes(f_value); 
            return ByteReverse_int(data);
        }

        public static int ByteReverse_int(byte[] f_data)
        {
            for (int i = 0; i < 2; ++i)
            {
                byte tmp = f_data[i];
                f_data[i] = f_data[3 - i];
                f_data[3 - i] = tmp;
            }
            return BitConverter.ToInt32(f_data, 0);
        }


        public static uint ByteReverse_uint(uint f_value)
        {
            byte[] data = BitConverter.GetBytes(f_value);
            return ByteReverse_uint(data);
        }

        public static uint ByteReverse_uint(byte[] f_data)
        {
            for (int i = 0; i < 2; ++i)
            {
                byte tmp = f_data[i];
                f_data[i] = f_data[3 - i];
                f_data[3 - i] = tmp;
            }
            return BitConverter.ToUInt32(f_data, 0);
        }

        public static void MemMove(byte[] f_buff, int f_sourceIndex, int f_destIndex, int f_len)
        {
            for (int i = 0; i < f_len; ++i)
            {
                f_buff[i + f_destIndex] = f_buff[i + f_sourceIndex];
            }
        }

    }
}